using System;
using dnAnalytics.Nli;

/// <summary>
/// Matrix multiplication. c = alpha * a * b + beta * c.
/// </summary>
internal class Program {
	[STAThread]
	private static void Main() {
		//use the MKL BLAS provider
		IBlas blas = Blas.Provider(BlasProvider.Mkl);

		/*
		    1 1 1 1 1       1 1 1               15 15 15              15 30 45
		a = 2 2 2 2 2   b = 2 2 2   a * b = c = 30 30 30  b'*a' = c = 15 30 45
		    3 3 3 3 3       3 3 3               45 45 45              15 30 45
			                4 4 4
							5 5 5
		*/

		//row ordering
		double[] a = new double[] {1, 2, 3, 1, 2, 3, 1, 2, 3, 1, 2, 3, 1, 2, 3};
		double[] b = new double[] {1, 2, 3, 4, 5, 1, 2, 3, 4, 5, 1, 2, 3, 4, 5};
		double[] c = new double[] {0, 0, 0, 0, 0, 0, 0, 0, 0};

		double alpha = 1;
		double beta = 0;

		///c = a * b
		blas.Dgemm(BlasOrderType.Column, BlasTransType.NoTrans, BlasTransType.NoTrans, 3, 3, 5, alpha, a, 3, b, 5, beta, c, 3);
		foreach (double value in c) {
			Console.WriteLine(value);
		}
		Console.WriteLine();

		///c = b'*a'
		blas.Dgemm(BlasOrderType.Column, BlasTransType.Trans, BlasTransType.Trans, 3, 3, 5, alpha, b, 5, a, 3, beta, c, 3);
		foreach (double value in c) {
			Console.WriteLine(value);
		}
		Console.WriteLine();

		/* 
		Output:
		15
		30
		45
		15
		30
		45
		15
		30
		45

		15
		15
		15
		30
		30
		30
		45
		45
		45		
		*/
	}
}